import { MessageBox, Message } from 'element-ui'

export const delModule = async (fn, message, params) => {
  await MessageBox.confirm(`此操作将永久删除该${message}, 是否继续?`, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  })
    .then(() => {
      const response = fn(params)
      response.then(res => {
        console.log(res)
        if (res.data.success || res.statusText === 'OK') {
          Message({
            type: 'success',
            message: '删除成功!'
          })
        } else {
          Message({
            type: 'error',
            message: '删除失败!'
          })
        }
      })
    })
    .catch(() => {
    })
}
